#include<iostream>
using namespace std;

long long GCD(long long a, long long b){
    for(long long c = a % b; c; c = a % b){
        a = b;
        b = c;
    }
    return b;
}

int main(){
    int T;
    
    for(cin >> T; T; T--){
        long long x, y;
        long long ans = -1;
        
        cin >> x >> y;
        for(long long z = y - 1; z > x; z--){
            if(GCD(x, z) == 1 && GCD(y, z) == 1){
                ans = z;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
} 
